package org.dxy.types.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用响应结果
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    
    /** 响应码 */
    private String code;
    
    /** 响应消息 */
    private String message;
    
    /** 响应数据 */
    private T data;
    
    /** 是否成功 */
    private boolean success;
    
    public static <T> Result<T> success() {
        return Result.<T>builder()
                .code("200")
                .message("操作成功")
                .success(true)
                .build();
    }
    
    public static <T> Result<T> success(T data) {
        return Result.<T>builder()
                .code("200")
                .message("操作成功")
                .data(data)
                .success(true)
                .build();
    }
    
    public static <T> Result<T> error(String message) {
        return Result.<T>builder()
                .code("500")
                .message(message)
                .success(false)
                .build();
    }
    
    public static <T> Result<T> error(String code, String message) {
        return Result.<T>builder()
                .code(code)
                .message(message)
                .success(false)
                .build();
    }
}